<template>
	<view class="news-list">
		<view class="news-items">
			<view class="news-item" v-for="(data,index) in list" :key="index" @click="goNewsInfo(data)">
				<image :src="data.image" mode="aspectFill"></image>
				<view class="news-info">
					<view class="name">{{data.name}}</view>
					<view class="brief">{{data.brief}}</view>
					<view class="time">
						<view class="click"><u-icon name="eye" color="#ccc" size="32" style="margin-right: 6rpx;"></u-icon>{{data.click}}</view>
						<view class="date">{{data.add_time}}</view>
					</view>
				</view>
			</view>
		</view>
		<pt-nothing bgColor="transparent" v-if="!list.length && noMore"></pt-nothing>
		<pt-loading-more v-if="loadingMore"></pt-loading-more>
		<pt-nomore v-if="noMore && list.length"></pt-nomore>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 0,
				noMore: false,
				loadingMore: false,
				list: []
			}
		},
		onReachBottom() {
			if(!this.loadingMore && !this.noMore){
				this.page++
				this.init()
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			async init(){
				let res = await this.$u.api.informationList({page: this.page,class_id: 1,order_by: 'add_time',asc: 2})
				this.list = this.page==0?res.datas:this.list.concat(res.datas)
				this.loadingMore = false
				this.noMore = this.list.length >= res.counts
			},
			goNewsInfo(data){
				if(data.type==1){
					uni.navigateTo({
						url: `/pages/webview/webview?url=${encodeURIComponent(data.url)}`
					})
				}else{
					uni.navigateTo({
						url: `/merchant/news-info/news-info?information_id=${data.information_id}`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.news-items{
		padding: 0 30rpx;
		.news-item{
			display: flex;
			align-items: flex-start;
			padding: 30rpx 0;
			border-bottom: solid 2rpx #E1E1E1;
			&:last-child{
				border-bottom: none;
			}
			image{
				width: 160rpx;
				height: 160rpx;
				border-radius: 15rpx;
			}
			.news-info{
				flex: 1;
				min-width: 0;
				margin-left: 16rpx;
				.name{
					font-size: 34rpx;
					font-weight: bold;
					overflow: hidden;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
				.brief{
					font-size: 24rpx;
					line-height: 32rpx;
					margin-top: 12rpx;
					overflow: hidden;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
				.time{
					display: flex;
					align-items: center;
					margin-top: 19rpx;
					color: #ccc;
					font-size: 20rpx;
					.click{
						display: flex;
						align-items: center;
					}
					.date{
						margin-left: 16rpx;
					}
				}
			}
		}
	}
</style>
